<template>
  <div class="batchSubmit">
    <p class="title">{{ companyName }}</p>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column prop="yund_id" label="运单ID" align="center"></el-table-column>
      <el-table-column prop="cph" label="车牌号" align="center"></el-table-column>
      <el-table-column prop="money_bill" label="含税金额(元)" align="center" class-name="money_bill"></el-table-column>
      <el-table-column prop="money" label="实结金额(元)" align="center" class-name="money"></el-table-column>
      <el-table-column prop="shkg" label="收货重量" align="center"></el-table-column>
    </el-table>
    <div class="info">
      <p class="info-item">总含税金额: <span style="color: red;font-weight:bold">{{totalBillMoney}} </span>元</p>
      <p class="info-item">总实结金额: <span style="color: green;font-weight:bold">{{totalMoney}} </span>元</p>
    </div>
    <div class="tool">
      <el-button class="toolBtn" @click="$emit('close')">取消</el-button>
      <el-button class="toolBtn" type="primary" @click="sure">确 定</el-button>
    </div>
  </div>
</template>

<script>
import {batchSubmitApplication} from "@/api/childCompany/moneyManagment"
import Big from "big.js";
export default {
  name: "batchSubmit",
  props: {
    rows: {
      default: [],
      type: Array
    }
  },
  data() {
    return {
      tableData: [],
      companyName:'',
      totalMoney:0,
      totalBillMoney:0,
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      console.log("rows", this.rows);
      this.tableData = this.rows;
      this.companyName =  this.tableData[0].company;
      this.totalMoney = this.rows.reduce((p, c) => {
        let money = new Big(c.money);
        let _p = new Big(p);
        return _p.plus(money).toNumber();
      }, 0);
      this.totalBillMoney = this.rows.reduce((p, c) => {
        let money_bill = new Big(c.money_bill);
        let _p = new Big(p);
        return _p.plus(money_bill).toNumber();
      }, 0);
    },
    async sure(){
      let result = await batchSubmitApplication({
        yund_id:this.rows.map(item=>item.yund_id).join(','),
        company:this.companyName,
        money:this.totalMoney
      });
      if(result.code == 200){
        this.$message.success('批量发起审批成功!');
        setTimeout(()=>{
          this.$emit('refresh');
        },500)
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.batchSubmit {
.title{
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 10px;
}
.info{
  display: flex;
  margin-top: 20px;
  justify-content: center;
  .info-item{
    font-size: 20px;
    margin-right: 20px;
  }
}
  .tool{
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
}
</style>

